package com.zt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zt.dao.EmployeeLoginLogdao;
import com.zt.dao.Employeedao;
import com.zt.service.EmployeeLoginLogService;
import com.zt.utils.Query;
import com.zt.utils.Result;
import org.example.systemset_pojo.Employee;
import org.example.systemset_pojo.EmployeeLoginLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeLoginLogServiceImpl extends ServiceImpl<EmployeeLoginLogdao, EmployeeLoginLog> implements EmployeeLoginLogService {
    @Autowired
    private EmployeeLoginLogdao employeeLoginLogdao;
    @Autowired
    private Employeedao employeedao;
    @Override
    public Page<EmployeeLoginLog> selectpage(Query query) {
        Page<EmployeeLoginLog> page = new Page<>(query.getPage(),query.getSize());
        employeeLoginLogdao.selectPage(page,null);
        List<EmployeeLoginLog> records = page.getRecords();
        if (records.size()>0){
            for (EmployeeLoginLog e : records) {
                Integer id = e.getEmployeeId();
                Employee employee = employeedao.selectById(id);
                if (employee != null) {
                    e.setEmployeeName(employee.getName());
                } else {
                    e.setEmployeeName(""); // 默认值
                }
            }
        }
        return page;
    }
}
